package org.spindle.dungeon.entities;


import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.spindle.dungeon.EntityManager;
import org.spindle.dungeon.LevelProperties;

public class Worm extends GeneralEntity {

    public static final int SPEED = 2;
    public int numMoves = 1;
    public int speed = 2;

    @Override
    protected void initialize() {
        //up
        animations[0] = new Animation(getAnimationArray(2, 18, 3), 200);

        //down
        animations[1] = new Animation(getAnimationArray(2, 16, 3), 200);

        //right
        animations[2] = new Animation(getAnimationArray(2, 19, 3), 200);

        //left
        animations[3] = new Animation(getAnimationArray(2, 17, 3), 200);

        direction = (int) Math.round(Math.random() * 3);
        lifeTime = 40;

    }

    @Override
    public void update(GameContainer gc, LevelProperties props) {

        if (speed-- < 0) {
            if (--numMoves < 0) {
                direction = (int) Math.round(Math.random() * 3);
                numMoves = (int) Math.round(40 + Math.random() * 100);
            }

            if (!doGeneralAIDirectionMove()) {
                numMoves = 0;
            }
            speed = SPEED;
        }


    }
}
